package com.biz.primus.app.rest.controller.geo;

import com.biz.primus.app.rest.controller.base.RestBaseController;
import com.biz.primus.app.rest.feign.GeoFeignClient;
import com.biz.primus.base.support.rest.vo.JsonResult;
import com.biz.primus.model.geo.vo.AreaResponseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * GeoController
 *
 * @author JKLiues
 * @date 2017年11月14日
 */
@RestController
@RequestMapping("geo")
public class GeoController extends RestBaseController {

    private final GeoFeignClient geoFeignClient;

    @Autowired
    public GeoController(GeoFeignClient geoFeignClient) {
        this.geoFeignClient = geoFeignClient;
    }

    /**
     * 返回中国所有省的列表
     *
     * @return List<AreaResponseVo>
     */
    @ApiOperation(value = "所有省的列表", responseContainer = "List", response = AreaResponseVo.class)
    @GetMapping("findAllProvince")
    public JsonResult findAllProvince() {
        List<AreaResponseVo> allProvince = geoFeignClient.findAllProvince();
        return new JsonResult(allProvince);
    }

    /**
     * 根据省id 获取该省所有市的 volist
     *
     * @param provinceId 省ID
     * @return List<AreaResponseVo>
     */
    @ApiOperation(value = "根据省id 获取该省所有市的", responseContainer = "List", response = AreaResponseVo.class)
    @GetMapping("soa/geoService/findCitiesByProvinceId")
    public JsonResult findCitiesByProvinceId(@RequestParam("provinceId") Long provinceId) {
        List<AreaResponseVo> citiesByProvinceId = geoFeignClient.findCitiesByProvinceId(provinceId);
        return new JsonResult(citiesByProvinceId);
    }

    /**
     * 根据市id获取该市所有的区
     *
     * @param cityId 市ID
     * @return List<AreaResponseVo>
     */
    @ApiOperation(value = "根据市id获取该市所有的区", response = AreaResponseVo.class, responseContainer = "List")
    @GetMapping("soa/geoService/findDistrictsByCityId")
    public JsonResult findDistrictsByCityId(@RequestParam("cityId") Long cityId) {
        List<AreaResponseVo> districtsByCityId = geoFeignClient.findDistrictsByCityId(cityId);
        return new JsonResult(districtsByCityId);
    }
}